<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>资讯详情_frm</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css"/>
    <style>
		#main{
		    padding: 0 0.6em 1.5em 0.6em; color: #4c4c4c;
		}
		#main h1{
			margin-top: 0px;
			margin-bottom: 0px;
			padding-top: 20px;
			padding-bottom: 5px;
		    font-size: 1.25em;
		    line-height: 1.3em;
		    font-weight:bold;
		}
		#main label{
		    font-size: 0.8em; color: #2FA746; padding:0 0 0.8em 0;
		    border-bottom: 1px solid #d9d9d9; display: block;
		    margin-bottom: 2em;
		}
		#main label em{color: #4c4c4c;}
		#main img{
		    width: 100%; margin-bottom: 0.2em;
		}
		#content{
			word-break: break-all; word-wrap:break-word;	/* 自动换行 */
		}
		
		p{ color: #4c4c4c; }
		
		.font_size_1, .font_size_1 p{
			font-size: 1em;
			line-height: 1.6em;
		}
		.font_size_2, .font_size_2 p{
			font-size: 1.1em;
			line-height: 1.7em;
		}
		.font_size_3, .font_size_3 p{
			font-size: 1.2em;
			line-height: 1.7em;
		}
		.font_size_4, .font_size_4 p{
			font-size: 1.3em;
			line-height: 1.8em;
		}
		
		
		/* 文本内容格式化  下面样式是从osc官网弄来的*/

		.TextContent pre {
			margin: 10px 0;
			font-size: 9pt;
			font-family: Courier New, Arial;
			border: 1px solid #ddd;
			border-left: 5px solid #6CE26C;
			background: #f6f6f6;
			padding: 5px;
			white-space: pre-wrap;
			white-space: -moz-pre-wrap;
			white-space: -pre-wrap;
			white-space: -o-pre-wrap;
			word-wrap: break-word;
		}
		
		.TextContent code {
			margin: 0 2px;
			padding: 0 5px;
			white-space: nowrap;
			border: 1px solid #DDD;
			background-color: #F6F6F6;
			border-radius: 3px;
		}
		
		.TextContent pre>code {
			margin: 0;
			padding: 0;
			white-space: pre;
			border: none;
			background: transparent;
		}
		
		.TextContent pre code {
			background-color: transparent;
			border: none;
		}
		
		.TextContent ol,.TextContent ul {
			margin: 20px 0 20px 20px;
			list-style-position: inside;
		}
		
		.TextContent ol {
			list-style-type: decimal;
			margin: 0.5em 0 0.5em 1.5em;
		}
		
		.TextContent ul {
			list-style-type: disc;
			margin: 0.5em 0 0.5em 1.5em;
		}
		
		.TextContent p {
			margin-bottom: 15pt;
		}
		
		.TextContent li p {margin-bottom:0;display:inline;}
		
		.TextContent h1,.TextContent h2,.TextContent h3 {
			margin-bottom: 10pt;
		}
		
		.TextContent h1 {
			font-size: 16pt;
		}
		
		.TextContent h2 {
			font-size: 14pt;
		}
		
		.TextContent h3 {
			font-size: 12pt;
		}
    </style>
</head>
<body>
	<div class="aui-content">
        <div id="main">
                <h1 id="title"></h1>
                <label id="info"></label>
            	<div id="content" class="TextContent font_size_2">
            	</div>
        </div>
	</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/OSChinaApi.js" ></script>
<script type="text/javascript" src="../script/common.js" ></script>
<script type="text/javascript">
	var pageParam, imageUrls, img_index;
	apiready = function(){
		pageParam = api.pageParam;
		getDetail( pageParam.id );
	};
	
	function getDetail( id ){
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '加载中...',
		    text: '',
		    modal: true
		});
	
		imageUrls = [];
		img_index = 0;
		
		var url = OpenAPI.news_detail + '?id=' + id;
		api.ajax({
		    url: url,
		    method: 'get',
		    timeout: 30,
		    dataType: 'text',
		    returnAll:false,
		},function(ret,err){
			api.hideProgress();
		    if (ret) {
				var trans = api.require('trans');
				trans.parse({
				    data:ret
				},function(ret,err){
				    if(ret) {
				    
				    	// 设置 win 的收藏图标状态
						api.execScript({
						    name: 'news_detail_win',
						    script: 'set_favorite_ico( '+ret.oschina.news.favorite+' )'
						});
				    
				    	// 把各个内容添加到页面中
				    	$api.text($api.byId('title'), ret.oschina.news.title);
						$api.html($api.byId('info'), ret.oschina.news.author+'　 <em>'+friendly_time(ret.oschina.news.pubDate)+'</em>');
				    	var body = strip_tags(ret.oschina.news.body, '<style><img><p><ul><li><ol><table><pre><code><h1><h2><h3>');
				    	
						// 图片浏览处理
						body.replace(/<img.*?src=\"(.*?)\"[^>]*>/ig, function(a, b) {
							body = body.replace(a, "<img onclick='imageBrowser("+img_index+")' src='"+b+"' />");
							imageUrls.push(b);
						    img_index++;
						});
				    	
				    	$api.html($api.byId('content'), body);
				    }else{
				        log(err.msg);
				    }
				});
		    }else {
		        log('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode);
		    	showAjaxErrMsg(err.code);
		    }
		});
	}
	
	// 浏览图片
	function imageBrowser(index){
			if("undefined" == typeof index){
				index = 0;
			}
			var obj = api.require('imageBrowser');
			obj.openImages({
			    imageUrls: imageUrls,
			    showList: false,
			    activeIndex: index
			});
	}

</script>
</html>